package learn.hibernate.bean.po;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.InheritanceType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.DynamicUpdate;

import com.fasterxml.jackson.annotation.JsonFilter;

    /**

    /**
    * @ClassName: PoResource
    * @Description: 测试多对多，其中多对多的关系由role 维护
    * @author 宁少林
    * @date 2016年8月27日
    *
    */
@Entity
@Table(name = "resource") //对应保存的数据库名称
@Inheritance(strategy =InheritanceType.JOINED)
@DynamicUpdate(true)	
/*@JsonFilter("myFilter")*/
//在Hibernate中可以利用@DynamicInsert和@DynamicUpdate生成动态SQL语句，即在插入和修改数据的时候,语句中只包括要插入或者修改的字段。
//当然还有其他的方式达到这种效果，比如使用session为我们提供的merge方法，也是可以的。
public class PoResource {
	private int id;
	
	
	    /**
	    * @Fields url : 实际上对应的是servletPath
	    */
	private String url;
	
	private String iron;
	
	private String description;
	
	private String name;
	
    /**
	    * @Fields type : 描述资源类型:
	    * 1. jsp
	    * 2.subJsp
	    * 3.json
	    * 4.excel
	    * 5.operator 主要为操作
	    * 6.resourceContainer 资源容器
	    */
	private String type;
	
	
	    /**
	    * @Fields autType : 鉴权类别：public;protected,默认为protected
	    */
	private String aucType="protected";
	
	
	
	
	    /**
	    * @Fields jspPageSet : resource 所承载的jsp
	    */
	
	private List<PoRole> roleList=new ArrayList<>();

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getIron() {
		return iron;
	}

	public void setIron(String iron) {
		this.iron = iron;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getAucType() {
		return aucType;
	}

	public void setAucType(String aucType) {
		this.aucType = aucType;
	}
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "role_resource", joinColumns = { @JoinColumn(name = "RESOURCE_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID", nullable = false, updatable = false) })
	@Cascade({
        CascadeType.DETACH,
        CascadeType.MERGE,
        CascadeType.REFRESH,
        CascadeType.PERSIST,
        CascadeType.SAVE_UPDATE
	})
	//@ManyToMany(mappedBy="resourceList")
	//@Cascade({ CascadeType.ALL })
	public List<PoRole> getRoleList() {
		return roleList;
	}

	public void setRoleList(List<PoRole> roleList) {
		this.roleList = roleList;
	}

	@Override
	public String toString() {
		return "PoResource [id=" + id + ", url=" + url + ", iron=" + iron
				+ ", description=" + description + ", name=" + name + ", type="
				+ type + ", aucType=" + aucType + "]";
	}
	
	
	
}
